<template>
  <!-- #ifndef XT_PC -->
  <!-- #ifndef APP-PLUS -->
  <u-button
    v-if="!copy"
    :class="classCalc"
    :type="typeCalc"
    :size="sizeCalc"
    :shape="shape"
    :plain="plain"
    :loading="loading"
    :loading-text="loadingText"
    :custom-style="customStyle"
    @click="$emit('click', $event)"
  >
    <slot />
  </u-button>
  <!-- #endif -->
  <!-- #ifdef APP-PLUS -->
  <u-button
    v-if="!copy"
    :class="classCalc"
    :type="typeCalc"
    :size="sizeCalc"
    :shape="shape"
    :plain="plain"
    :text="text"
    :disabled="disabled"
    :custom-style="customStyle"
    @click="$emit('click', $event)"
  >
    <slot />
  </u-button>
  <!-- #endif -->
  <!-- #endif -->
  <!-- eslint-disable vue/no-multiple-template-root -->
  <!-- #ifdef XT_PC -->
  <el-button
    v-if="!copy"
    :class="classCalc"
    :type="typeCalc"
    :size="sizeCalc"
    :round="shape==='circle'"
    :plain="plain"
    :disabled="disabled"
    :loading="loading"
    :loading-text="loadingText"
    @click="$emit('click', $event)"
  >
    <slot />
  </el-button>
  <!-- #endif -->
  <view 
    v-else
    :title="copy"
    class="x-ba-primary x-fs-sm x-primary x-cursor-pointer"
    style="padding: 1px 4px; border-radius: 2px"
    @click="doCopy(copy)"
  >
    复制
  </view>
</template>

<script>
  export default {
    name: 'XButton',
    options: {
      virtualHost: true
    },
    props: {
      text: {
        type: String,
        default: undefined,
      },
      type: {
        type: String,
        default: 'default', // info / primary / error/ warning / success / text
      },
      size: {
        type: String,
        default: 'normal', // normal	/ large / mini
      },
      shape: {
        type: String,
        default: 'square', // square circle
      },
      disabled: {
        type: Boolean,
        default: false,
      },
      plain: {
        type: Boolean,
        default: false,
      },
      link: {
        type: Boolean,
        default: false,
      },
      customStyle: {
        type: Object,
        default: ()=>({}),
      },
      copy: {
        type: String,
        default: '',
      },
      loading: {
        type: Boolean,
        default: false,
      },
      loadingText: {
        type: String,
        default: '加载中',
      },
    },
    data() {
      return {
        
      }
    },
    computed: {
      classCalc() {
        let ret = {}
        // #ifndef XT_PC
        if(this.type==='text') ret.border = 'none'
        // #endif
        return ret||''
      },
      typeCalc() {
        let ret
        // #ifdef XT_PC
        ret = this.type==='error'?'danger':this.type
        // #endif
        // #ifndef XT_PC
        ret = this.type==='text'?'primary':this.type
        // #endif
        return ret||''
      },           
      sizeCalc() { 
        let ret = this.size
        // #ifdef XT_PC
        if(this.size==='normal') {
          return 'medium'
        }else if(this.size==='large') {
          return ''
        }
        // #endif
        return ret||''
      }
    },
    methods: {				
      doCopy(value) {
        uni.setClipboardData({
          data: value,
          showToast: false,
          success: ()=> {
            this.$x.notify.showToast('已复制')
          }
        })
      },
    }
  }
</script>

<style>
</style>